﻿// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="Problem5.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation.  All rights reserved. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// </copyright>
// <summary>
//   Defines the Problem5 type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
namespace EulerProblemsCSharp.Problems
{
    using System.Linq;

    /// <summary>
    /// Problem 5.
    /// </summary>
    public class Problem5 : ProblemBase
    {
        /// <summary>
        /// Gets Number.
        /// </summary>
        /// <value>
        /// The number.
        /// </value>
        public override int Number
        {
            get
            {
                return 5;
            }
        }

        /// <summary>
        /// Gets Description.
        /// </summary>
        /// <value>
        /// The description.
        /// </value>
        public override string Description
        {
            get
            {
                return "What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?.";
            }
        }

        /// <summary>
        /// Solves the problem.
        /// </summary>
        /// <returns>
        /// The solution.
        /// </returns>
        public override object Solve()
        {
            var query = from number in Enumerable.Range(19, 100000000)
                        select number * 20
                        into value
                                where value % 19 == 0
                                where value % 18 == 0
                                where value % 17 == 0
                                where value % 16 == 0
                                where value % 15 == 0
                                where value % 14 == 0
                                where value % 13 == 0
                                where value % 12 == 0
                                where value % 11 == 0
                                select value;             
            
            var answer = query.First();

            return answer;
        }
    }
}